using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;

public class TestHello : MonoBehaviour
{
    [DllImport("__Internal")]
    public static extern IntPtr TestFloatArray();

    [DllImport("__Internal")]
    public static extern void freeFloatArrayMemory(IntPtr memoryPtr);

    private void Awake()
    {
        IntPtr memoryPtr = TestFloatArray();

        // 读取内存中的数据
        int length = 4; // 假设长度为 4
        float[] readArray = new float[length];
        Marshal.Copy(memoryPtr, readArray, 0, length);

        // 输出读取的数据
        foreach (float value in readArray)
        {
            Debug.Log("Read value: " + value);
        }

        // 释放内存
        freeFloatArrayMemory(memoryPtr);
    }

    public void ReceiveFloatArray(float[] floatArray)
    {
        // 在这里处理接收到的 Float32Array 数据
        foreach (float value in floatArray)
        {
            Debug.Log("Received value: " + value);
        }
    }
}